package org.example;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.SimpleAnnotationValueVisitor8;
import javax.tools.Diagnostic;
import java.util.Set;
@SupportedAnnotationTypes("com.example.ValidInt")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class TestProcessor extends AbstractProcessor {
    @Override
    public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
        for (TypeElement typeElement : set) {
            Set<? extends Element> elementsAnnotatedWith = roundEnvironment.getElementsAnnotatedWith(typeElement);
            for (Element element : elementsAnnotatedWith) {
                ValidInt annotation = element.getAnnotation(ValidInt.class);
                if (annotation!=null){
//                    element.getEnclosingElement().accept(new Visitor(""),Element.)
                }
            }
        }
        return false;
    }

    private class Visitor extends SimpleAnnotationValueVisitor8<Void,Element>{

        private String msg;

        public Visitor(String msg) {
            this.msg = msg;
        }

        @Override
        public Void visitString(String s, Element element) {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,msg,element);
            return null;
        }
    }
}
